<template>
  <div>
    <a-select
      v-model="selected"
      show-search
      placeholder="请选择"
      option-filter-prop="children"
      @change="handleChange"
    >
      <a-select-option v-for="item in list" :key="item.id" :value="item.id">
        {{item.name}}
      </a-select-option>
    </a-select>
  </div>
</template>

<script>
  import { getCommodityLabelList } from '@/api/commodity'

  export default {
    name: 'ActivityLabelSelection',
    props: {
      value: {
        type: Number,
        default: null
      }
    },
    watch: {
      value: {
        handler: function (val) {
          this.selected = val
        },
        immediate: true
      }
    },
    created () {
      getCommodityLabelList().then(res => {
        this.list = res.data
      })
    },
    data () {
      return {
        selected: null,
        list: []
      }
    },
    methods: {
      filterOption (input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        )
      },
      handleChange (value) {
        this.$emit('change', value)
        this.$emit('input', value)
      }
    }
  }
</script>

<style scoped>

</style>
